package com.ja.openchat.adapters;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ja.openchat.R;
import com.ja.openchat.views.UserAvatarView;
import com.zy.openchat.core.manager.TelegramManager;
import com.zy.openchat.core.model.user.UserInfo;

import java.util.List;

public class UserGridAdapter extends BaseQuickAdapter<UserInfo, BaseViewHolder> {
    public UserGridAdapter(@Nullable List<UserInfo> data) {
        super(R.layout.adapter_grid_user, data);
        addChildClickViewIds(R.id.delete_button);
    }

    @Override
    protected void convert(BaseViewHolder helper, UserInfo member) {
        UserAvatarView avatarView = helper.getView(R.id.iv_icon);
        avatarView.setTextSize(23);
        helper.setGone(R.id.delete_button,true);
        if (member.isOptAdd()) {
            helper.setText(R.id.iv_title, " ");
            avatarView.showImage(R.drawable.group_member_add);
        } else if (member.isOptDel()) {
            helper.setText(R.id.iv_title, " ");
            avatarView.showImage(R.drawable.group_member_remove);
        } else {
            helper.setGone(R.id.delete_button,false);
            helper.setText(R.id.iv_title, UserInfo.userDisplayName(member.id));
            UserInfo user = TelegramManager.getTelegramManager().getTgData().contactInfo(member.id);
            if (user != null) {
                avatarView.showUser(user);
            } else {
                avatarView.showName(UserInfo.userDisplayName(member.id));
            }
        }

    }
}
